package a03demo3;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test1 {
    public static void main(String[] args) {
        String s = "Java自从95年问世以来，经历了很多版本，目前企业中用的最多的是Java8和Java11， " + "因为这两个是长期支持版本，" +
                "下一个长期支持版本是Java17，相信在未来不久Java17也会逐渐登上历史舞台";
        String regex1 = "((?i)Java)(?=8|11|17)";
        Pattern p1 = Pattern.compile(regex1);
        Matcher m1 = p1.matcher(s);
        while (m1.find()) {
            System.out.println(m1.group());
        }
        System.out.println("-----------------");

        String regex2 = "Java\\d{1,2}";
        Pattern p2 = Pattern.compile(regex2);
        Matcher m2 = p2.matcher(s);
        while (m2.find()) {
            System.out.println(m2.group());
        }
        System.out.println("-----------------");

        String regex3 = "((?i)Java)(8|11|17)";
        Pattern p3 = Pattern.compile(regex3);
        Matcher m3 = p3.matcher(s);
        while (m3.find()) {
            System.out.println(m3.group());
        }

        System.out.println("--------------------");
        String regex4 = "((?i)Java)(?:8|11|17)";
        Pattern p4 = Pattern.compile(regex4);
        Matcher m4 = p4.matcher(s);
        while (m4.find()) {
            System.out.println(m4.group());
        }

        System.out.println("-----------------");

        String regex5="((?i)Java)(?!8|11|17)";
        Pattern p5 = Pattern.compile(regex5);
        Matcher m5 = p5.matcher(s);
        while (m5.find()) {
            System.out.println(m5.group());
        }
    }
}
